//
//  RPLaunchScreenViewCell.m
//  ShowYork
//
//  Created by hxh on 2020/10/21.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "RPLaunchScreenViewCell.h"

@interface RPLaunchScreenViewCell ()
@property (nonatomic,strong)UIImageView *contentImgView;
@property (nonatomic,strong)UIImageView *centerImgView;
@property (nonatomic,strong)UIButton *loginBtn;
@property (nonatomic,strong)UIButton *otherBtn;
@property (nonatomic,strong)UILabel *mainTitleLb;
@property (nonatomic,strong)UILabel *subTitleLb;
@end

@implementation RPLaunchScreenViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.contentImgView = [[UIImageView alloc]init];

    [self.contentView addSubview:self.contentImgView];
    
    self.centerImgView = [[UIImageView alloc]init];
    self.centerImgView.contentMode = UIViewContentModeScaleAspectFit;
    self.centerImgView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.centerImgView];
    
    self.loginBtn = [[UIButton alloc]init];
    [self.loginBtn setTitle:@"登录/注册" forState:UIControlStateNormal];
    [self.loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.loginBtn.titleLabel.font = font(18);
    self.loginBtn.layer.cornerRadius = 22;
    self.loginBtn.layer.masksToBounds = YES;
    self.loginBtn.backgroundColor = [RPAppManager themColor];
    [self.loginBtn addTarget:self action:@selector(loginMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.loginBtn];
    
    self.otherBtn = [[UIButton alloc]init];
    [self.otherBtn setTitle:@"游客进入" forState:UIControlStateNormal];
    [self.otherBtn setTitleColor:[RPAppManager themColor] forState:UIControlStateNormal];
    self.otherBtn.titleLabel.font = font(18);
    self.otherBtn.layer.cornerRadius = 22;
    self.otherBtn.layer.borderColor = [RPAppManager themColor].CGColor;
    self.otherBtn.layer.borderWidth = 1;
    self.otherBtn.layer.masksToBounds = YES;
    self.otherBtn.backgroundColor = RGBA(86, 128, 250, 0.1);
    [self.otherBtn addTarget:self action:@selector(otherMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.otherBtn];
    
    
    self.mainTitleLb = [[UILabel alloc]init];
    self.mainTitleLb.textColor = C35;
    self.mainTitleLb.font = [UIFont boldSystemFontOfSize:24];
    [self.contentView addSubview:self.mainTitleLb];
    
    self.subTitleLb = [[UILabel alloc]init];
    self.subTitleLb.textColor = RGBA(125, 125, 125, 1);
    self.subTitleLb.font = font(16);
    [self.contentView addSubview:self.subTitleLb];
    
    [self.contentImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
    
    [self.centerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
    }];
    
    CGFloat btnWidth = (kScreenW - 32 * 2 - 16)/2;
    
    [self.otherBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(btnWidth, 44));
        make.bottom.equalTo(self.contentView).offset(-(70 + GK_SAVEAREA_BTM));
        make.left.equalTo(self.contentView).offset(32);
    }];
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(btnWidth, 44));
        make.bottom.equalTo(self.contentView).offset(-(70 + GK_SAVEAREA_BTM));
        make.left.equalTo(self.otherBtn.mas_right).offset(16);
    }];

    [self.mainTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(kNavBarHeight + 16);
        make.centerX.equalTo(self.contentView);
    }];
    [self.subTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mainTitleLb.mas_bottom).offset(12);
        make.centerX.equalTo(self.contentView);
    }];
    
    self.otherBtn.hidden = YES;
    self.loginBtn.hidden = YES;
}

- (void)loginMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showLogin)]) {
        [self.delegate showLogin];
    }
}

- (void)otherMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showOther)]) {
        [self.delegate showOther];
    }
}

- (void)setScreenMainTitle:(NSString *)mainTitle subTitle:(NSString *)subTitle showButton:(BOOL)show index:(NSInteger)index{
    self.otherBtn.hidden = !show;
    self.loginBtn.hidden = !show;
    self.centerImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"launch_screen_bg%lu_tag",index]];
    self.contentImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"launch_screen%lu_tag",index]];
    self.mainTitleLb.text = mainTitle;
    self.subTitleLb.text = subTitle;
}

@end
